package com.hyt.it.ogt.controller.ykcj.analysis;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hyt.common.apiInfor.DataType;
import com.hyt.common.apiInfor.ParamType;
import com.hyt.it.ogt.controller.base.BaseController;
import com.hyt.it.ogt.ykcj.common.core.domain.AjaxResult;
import com.hyt.it.ogt.ykcj.common.core.domain.entity.SysUser;
import com.hyt.it.ogt.ykcj.common.enums.BizErrorCode;
import com.hyt.it.ogt.ykcj.common.utils.ServletUtils;
import com.hyt.it.ogt.ykcj.domain.vo.analysis.ScoreLinePointVo;
import com.hyt.it.ogt.ykcj.framework.web.service.TokenService;
import com.hyt.it.ogt.ykcj.service.analysis.IExamScoreAnalysisLineService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiSort;

/**
 * description
 *
 * @author yaojian
 * @createTime 2021/12/31
 */
@Api(tags = "ScoreAnalysis.15.分数段统计分析", value = "分数段")
@ApiSort(value = 210)
@RestController
@RequestMapping("/score/analysis")
public class ExamScoreAnalysisLineController extends BaseController {

    @Autowired
    private IExamScoreAnalysisLineService examScoreAnalysisLineService;
    @Autowired
    private TokenService tokenService;

    /**
     * 获取考试分数段信息
     */
    @ApiOperation("获取考试分数段信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "examId", value = "考试ID", dataType = DataType.STRING,paramType = ParamType.PATH, required = true),
    })
    @GetMapping(value = "/{examId}")
    public AjaxResult get(@PathVariable("examId") String examId) throws Exception {
        if (StringUtils.isEmpty(examId)) {
            return AjaxResult.error(BizErrorCode.EXAM_E0002.getErrMsg());
        }
        return AjaxResult.success(examScoreAnalysisLineService.selectScoreLineById(examId));
    }

    /**
     * 新增或修改考试分数段信息
     */
    @ApiOperation("新增或修改考试分数段信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "examId", value = "考试id", dataType = "String", required = true),
            @ApiImplicitParam(name = "minScore", value = "极限最小值", dataType = "String", required = true),
            @ApiImplicitParam(name = "maxScore", value = "极限最大值", dataType = "String", required = true),
            @ApiImplicitParam(name = "pointScoreList", value = "分数段列表", dataType = DataType.ARRAY, required = true),
    })
    @PostMapping(value = "/saveOrUpdate")
    public AjaxResult saveOrUpdate(@RequestBody @Validated ScoreLinePointVo scoreLinePointVo) {
        SysUser user = tokenService.getSysUser(ServletUtils.getRequest());
        return AjaxResult.success(examScoreAnalysisLineService.saveOrUpdate(scoreLinePointVo));
    }

}
